﻿package mortal.game.view.monthInvestment.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class MonthInvestGetCellRender extends GCellRenderer
    {
        private var _bg:GImageBitmap;
        private var _item:BaseItem;
        private var _isGetIcon:GImageBitmap;
        private var _rewardName:GImageBitmap;
        private var _stateIcon:GImageBitmap;
        private var _dayNum:GTextFiled;
        private var _rewardNum:BitmapNumberText;
        private var _tinvest:TInvest;
        private var _type:int;
        private var _getInvestBtn:GLoadingButton;

        public function MonthInvestGetCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.MonthInvestGetBg, 0, 0, this);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.setItemStyle(62, null, 0, 0);
            this._item.isShowColorBg = false;
            this._item.isShowLock = false;
            var _loc_2:Boolean = false;
            this._item.isDropAble = false;
            this._item.isDragAble = _loc_2;
            this._item.x = (this.width - this._item.width) * 0.5 + 30;
            this._item.y = 58;
            this.addChild(this._item);
            this._rewardNum = UIFactory.bitmapNumberText(45, 123, "MonthInvestValNumber.png", 10, 30, 1, this, 9);
            this._rewardName = UIFactory.gImageBitmap("", 56, 121, this, this.resetRwardNamePos);
            this._stateIcon = UIFactory.gImageBitmap("", 0, 156, this, this.resetStateIconPos);
            var _loc_1:* = GlobalStyle.textFormatLv;
            this._dayNum = UIFactory.gTextField("", 27, 10, 66, 20, this, _loc_1);
            this._isGetIcon = UIFactory.gImageBitmap("", 50, 51, this, this.resetIsGetIconPos);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._item.dispose(param1);
            this._item = null;
            this._dayNum.dispose(param1);
            this._dayNum = null;
            this._rewardName.dispose(param1);
            this._rewardName = null;
            this._isGetIcon.dispose(param1);
            this._isGetIcon = null;
            this._rewardNum.dispose(param1);
            this._rewardNum = null;
            this._stateIcon.dispose(param1);
            this._stateIcon = null;
            this.removeGetInvestBtn();
            this._tinvest = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function resetIsGetIconPos() : void
        {
            this._isGetIcon.x = (this.width - this._isGetIcon.width) * 0.5;
            return;
        }// end function

        private function resetStateIconPos() : void
        {
            this._stateIcon.x = (this.width - this._stateIcon.width) * 0.5;
            return;
        }// end function

        private function resetRwardNamePos() : void
        {
            if (this._rewardNum)
            {
                this._rewardNum.x = this.width - this._rewardNum.width - this._rewardName.width >> 1;
            }
            this._rewardName.x = this._rewardNum.x + this._rewardNum.width;
            return;
        }// end function

        private function getInvestment(event:MouseEvent) : void
        {
            var _loc_2:* = _data.index + 1;
            var _loc_3:Object = {operType:EInvestOper._EInvestGetToday, type:this._type, day:_loc_2};
            Dispatcher.dispatchEvent(new DataEvent(EventName.InvestmentGet, _loc_3));
            return;
        }// end function

        private function addGetInvestBtn() : void
        {
            if (this._getInvestBtn == null)
            {
                this._getInvestBtn = UIFactory.gLoadingButton(ResFileConst.MonthInvestGetBtn, 28, 149, 106, 32, this);
                this._getInvestBtn.configEventListener(MouseEvent.CLICK, this.getInvestment);
            }
            return;
        }// end function

        private function removeGetInvestBtn() : void
        {
            if (this._getInvestBtn)
            {
                EffectManager.glowFilterUnReg(this._getInvestBtn);
                this._getInvestBtn.dispose();
                this._getInvestBtn = null;
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:SInvestInfo = null;
            super.data = param1;
            this._type = param1.type;
            var _loc_2:* = param1.index;
            _loc_3 = Cache.instance.investment.getTodayInfoByType(this._type, (_loc_2 + 1));
            this._dayNum.text = Language.getStringByParam(35408, (_loc_2 + 1));
            this._dayNum.x = (this.width - this._dayNum.textWidth) * 0.5;
            this._tinvest = MonthInvestmentConfig.instance.rewardArr[this._type][_loc_2] as TInvest;
            this._rewardNum.text = this._tinvest.rewardNum.toString();
            if (_loc_3)
            {
                if (_loc_3.isGetToday)
                {
                    this.filters = [];
                    this._isGetIcon.imgUrl = ImagesConst.MonthInvestGetSuccess;
                    this._stateIcon.imgUrl = ImagesConst.MonthInvestGetSuccess2;
                    this.mouseEnabled = false;
                    this.removeGetInvestBtn();
                }
                else
                {
                    this.filters = [];
                    this._isGetIcon.imgUrl = ImagesConst.MonthInvestCanGet;
                    this._stateIcon.imgUrl = "";
                    this.mouseEnabled = true;
                    this.addGetInvestBtn();
                    EffectManager.glowFilterReg(this._getInvestBtn);
                    this._getInvestBtn.filterEnabled = true;
                }
            }
            else
            {
                this._stateIcon.imgUrl = "";
                this._isGetIcon.imgUrl = "";
                this.filters = [FilterConst.colorFilter2];
                this.mouseEnabled = false;
                this.addGetInvestBtn();
                EffectManager.glowFilterUnReg(this._getInvestBtn);
                this._getInvestBtn.filterEnabled = false;
            }
            if (this._tinvest.reward >= 1000)
            {
                this._item.itemData = new ItemData(this._tinvest.reward);
            }
            else
            {
                this._item.toolTipData = GameDefConfig.instance.getEPrictUnitName(this._tinvest.reward);
            }
            this._item.source = "monthInvestTypeIcon_" + this._type + ".png";
            this._rewardName.imgUrl = "monthInvestTypeNameSmall_" + this._type + ".png";
            this.resetRwardNamePos();
            return;
        }// end function

    }
}
